package br.livro.android.cap8.filtro;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.ImageView;

public class AdaptadorImagem extends BaseAdapter {

	private List<ImageView> smiles;
	private Context context;
	private LayoutParams params;

	public AdaptadorImagem(Context context, List<ImageView> list,
			LayoutParams params) {
		this.context = context;
		smiles = list;
		this.params = params;
	}

	public AdaptadorImagem(Context context, List<ImageView> list) {
		this.context = context;
		smiles = list;
		params = null;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return smiles.size();
	}

	@Override
	public Object getItem(int arg0) {

		return smiles.get(arg0);
	}

	@Override
	public long getItemId(int posicao) {
		return posicao;
	}

	@Override
	public View getView(int posicao, View arg1, ViewGroup arg2) {
		ImageView imageView = new ImageView(context);
		imageView.setImageResource(smiles.get(posicao).getBaseline());
		
		imageView.setAdjustViewBounds(true);
		if (this.params != null) {
			/*
			 * new GridView.LayoutParams(30,30) ->
			 * sets the height and width for the View (this case is ImageView).
			 * this ensures that, no matter [nao importa] the size of the drawable, each image is resized and
			 * cropped to fit in these dimensions, as appropriate.
			 */
			imageView.setLayoutParams(params);
		}
		return imageView;
	}

}
